/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package vettsspammer;

import java.util.ArrayList;
import test.Shipyard;

/**
 *
 * @author Luca
 */
public class VettsCalculatorFrame extends javax.swing.JFrame {
    
    private final int BASETIME = 11070;
    

//    int [] howmanyships;
//    int [] levels;
//    int startTime = 11070;
    /**
     * Creates new form VettsCalculatorFrame
     */
    public VettsCalculatorFrame() {
        initComponents();
    }
//    
//    private double speed(int level){
//        return 100 * Math.pow(1.2 , (level-1));
//    }
//    
//    private int buildTime(int level) {
//        return (int) (startTime * (100 / speed(level)));
//    }
//
//    private void calculate (int [] levels){
//        this.levels = levels;
//        howmanyships = new int[levels.length];
//        
//    }
    
//    public void calculate(int num, int lvl1, int lvl2, int lvl3) {
//        int firstShipyardTimePerVett = timePerVett(lvl1);
//        int secondShipyardTimePerVett = timePerVett(lvl2);
//        int thirdShipyardTimePerVett = timePerVett(lvl3);
//        
//        int firstFinalTime = 0;
//        int secondFinalTime = 0;
//        int thirdFinalTime = 0;
//        
//        int firstFinalAmount = 0;
//        int secondFinalAmount = 0;
//        int thirdFinalAmount = 0;
//        
//        for(int i = 0; i < num; i++) {
//            if(firstFinalTime <= secondFinalTime && firstFinalTime <= thirdFinalTime) {
//                firstFinalTime += firstShipyardTimePerVett;
//                firstFinalAmount++;
//            } else if(secondFinalTime <= thirdFinalTime) {
//                secondFinalTime += secondShipyardTimePerVett;
//                secondFinalAmount++;
//            } else {
//                thirdFinalTime  += thirdShipyardTimePerVett;
//                thirdFinalAmount++;
//            }
//        }
//        
//        System.out.println("Build "+ firstFinalAmount +" corvettes with your level "+ lvl1 +" shipyard.");
//        System.out.println("Build "+ secondFinalAmount +" corvettes with your level "+ lvl2 +" shipyard.");
//        System.out.println("Build "+ thirdFinalAmount +" corvettes with your level "+ lvl3 +" shipyard.");
//        printTime(Math.max( Math.max(firstFinalTime,secondFinalTime) , thirdFinalTime));
//    }
    
    public void calculate(int num, int lvl1, int lvl2, int lvl3) {
        ArrayList<Shipyard> shipyards = new ArrayList<>();
        shipyards.add(new Shipyard(lvl1));
        shipyards.add(new Shipyard(lvl2));
        shipyards.add(new Shipyard(lvl3));
        
        test.BuildBackend.calculate(shipyards, num);
        
        for (Shipyard shipyard : shipyards) {
            shipyard.printInfo();
        }
    }
    
//    private int timePerVett(int level) {
//        return (int) (Math.round(BASETIME / Math.pow(1.2, (level - 1))));
//    }
//    
//    private void printTime(int time) {
//        int days = (int) (Math.floor(time / 86400));
//        int hours = (int) (Math.floor(time / 3600) % 24);
//        int minutes = (int) (Math.floor(time / 60) % 60);
//        int seconds = time % 60;
//        String formattedTime = "It will take ";
//        int var = 0;
//        
//        if(days > 0) var++;
//        if(hours > 0) var++;
//        if(minutes > 0) var++;
//        if(seconds > 0) var++;
//        
//        if(var == 2) {
//            if(days > 0) {
//                var--;
//                formattedTime = formattedTime + days + " " + checkPlural("day", days) +" and ";
//            }
//            if(hours > 0) {
//                var--;
//                formattedTime = var == 1 ? formattedTime + hours + " " + checkPlural("hour", hours) +" and " : formattedTime + hours + checkPlural("hour", hours) +".";
//            }
//            if(minutes > 0) {
//                var--;
//                formattedTime = var == 1 ? formattedTime + minutes + " " + checkPlural("minute", minutes) +" and " : formattedTime + minutes + checkPlural("minute", minutes) +".";
//            }
//            if(seconds > 0) {
//                formattedTime = formattedTime + seconds + " " + checkPlural("second", seconds) +".";
//            }
//        } else {
//            if(days > 0) {
//                var--;
//                formattedTime = formattedTime + days + " " + checkPlural("day", days) + checkTimeline(var);
//            }
//            if(hours > 0) {
//                var--;
//                formattedTime = formattedTime + hours + " " + checkPlural("hour", hours) + checkTimeline(var);
//            }
//            if(minutes > 0) {
//                var--;
//                formattedTime = formattedTime + minutes + " " + checkPlural("minute", minutes) + checkTimeline(var);
//            }
//            if(seconds > 0) {
//                formattedTime = formattedTime + seconds + " " + checkPlural("second", seconds) +".";
//            }
//        }
//        
//        System.out.println(formattedTime);
//        
//    }
//    
//    // checks for what puntuation is needed
//    private String checkTimeline(int var) {
//        String addition;
//        if(var == 0) {
//            addition = ".";
//        } else if(var == 1) {
//            addition = ", and ";
//        } else {
//            addition = ", ";
//        }
//        return addition;
//    }
//    
//    private String checkPlural(String measurement, int amount) {
//        if(measurement.contains("day")) {
//            return amount == 1 ? "day" : "days";
//        } else if(measurement.contains("hour")) {
//            return amount == 1 ? "hour" : "hours";
//        } else if(measurement.contains("minute")) {
//            return amount == 1 ? "minute" : "minutes";
//        } else if(measurement.contains("second")) {
//            return amount == 1 ? "second" : "seconds";
//        } else {
//            return "error";
//        }
//    }
    

//TIMEONE=0
//TIMETWO=0
//TIMETHREE=0
//LENGTHONE=1490
//LENGTHTWO=1035
//
//while [ $MADE -lt $1 ]; do
//	((MADE++))
//	if [ $TIMEONE -le $TIMETWO ]; then
//		((TIMEONE+=LENGTHONE))
//		((NUMONE++))
//	elif [ $TIMETWO -le $TIMETHREE ]; then
//		((TIMETWO+=LENGTHTWO))
//		((NUMTWO++))
//	else
//		((TIMETHREE+=LENGTHONE))
//		((NUMTHREE++))
//	fi
//
//    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTextField_howManyVetts = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("How many vetts you want to craft ? ");

        jTextField_howManyVetts.setText("0");

        jLabel2.setText("First Shipyard's level?");

        jLabel3.setText("Second Shipyard's level?");

        jLabel4.setText("Third Shipyard's level?");

        jButton1.setText("Calculate");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "12", "13", "14", "15", "16", "17", "18", "19", "20" }));

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "12", "13", "14", "15", "16", "17", "18", "19", "20" }));

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "12", "13", "14", "15", "16", "17", "18", "19", "20" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField_howManyVetts, javax.swing.GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE)
                    .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jComboBox3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(141, 141, 141)
                .addComponent(jButton1)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField_howManyVetts, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        int howManyVetts = Integer.parseInt(this.jTextField_howManyVetts.getText());
        int level1 = Integer.parseInt(this.jComboBox1.getSelectedItem().toString());
        int level2 = Integer.parseInt(this.jComboBox2.getSelectedItem().toString());
        int level3 = Integer.parseInt(this.jComboBox3.getSelectedItem().toString());
        
        calculate(
                howManyVetts,
                level1,
                level2,
                level3
        );
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
        // TODO add your handling code here:
//        calculate(49,12,14,12);
    }//GEN-LAST:event_jButton1MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VettsCalculatorFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VettsCalculatorFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VettsCalculatorFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VettsCalculatorFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VettsCalculatorFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField jTextField_howManyVetts;
    // End of variables declaration//GEN-END:variables
}
